using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.MedicalDomain;
using ShivamEMR.Model.DataInterfaces.MedicalDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Medical.Controllers
{   
    public class DiseaseCategoryController : Controller
    {
		private readonly IDiseaseCategoryRepository diseasecategoryRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public DiseaseCategoryController()// : this(new DiseaseCategoryRepository())
        {
            this.diseasecategoryRepository = Registry.RepositoryFactory.GetDiseaseCategoryRepository();
        }

        public DiseaseCategoryController(IDiseaseCategoryRepository diseasecategoryRepository)
        {
			this.diseasecategoryRepository = diseasecategoryRepository;
        }

        //
        // GET: /DiseaseCategory/

        public ViewResult Index()
        {
            return View(diseasecategoryRepository.All);//Including(diseasecategory => diseasecategory.Diseases));
        }

        //
        // GET: /DiseaseCategory/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(diseasecategoryRepository.Find(id));
        }

        //
        // GET: /DiseaseCategory/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /DiseaseCategory/Create

        [HttpPost]
        public ActionResult Create(DiseaseCategory diseasecategory)
        {
            if (ModelState.IsValid) {
                diseasecategoryRepository.InsertOrUpdate(diseasecategory);
                diseasecategoryRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /DiseaseCategory/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
             return View(diseasecategoryRepository.Find(id));
        }

        //
        // POST: /DiseaseCategory/Edit/5

        [HttpPost]
        public ActionResult Edit(DiseaseCategory diseasecategory)
        {
            if (ModelState.IsValid) {
                diseasecategoryRepository.InsertOrUpdate(diseasecategory);
                diseasecategoryRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /DiseaseCategory/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(diseasecategoryRepository.Find(id));
        }

        //
        // POST: /DiseaseCategory/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var d = diseasecategoryRepository.Find(id);
            diseasecategoryRepository.Delete(d);
            diseasecategoryRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

